package grafica;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JPanel;

public class ClassificaPanel extends JPanel implements KeyListener {
	
	MediaTracker mt;
	Toolkit t;
	Myframe mf;
	
	public ClassificaPanel(Myframe mf){
		super();
		this.setFocusable(true);
		this.addKeyListener(this);
		
		t= Toolkit.getDefaultToolkit();
		mt = new MediaTracker(this);
		mt.addImage(t.getImage("images/Menu/Classifica/spazio1.gif"),0);
		mt.addImage(t.getImage("images/Menu/Classifica/Classifica.png"),1);
		mt.addImage(t.getImage("images/Menu/menu.png"),2);
		mt.addImage(t.getImage("images/Menu/Esci.png"),3);
		this.mf = mf;
		this.requestFocus();
		
		try {
			mt.waitForAll();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void paintComponent(Graphics g) {
		g.fillRect(0, 0, Myframe.SCREEN_WIDTH, Myframe.SCREEN_HEIGHT);
		g.drawImage(t.getImage("images/Menu/Classifica/spazio1.gif"), 0, 0, null);
		//this.repaint();
		g.drawImage(t.getImage("images/Menu/Classifica/Classifica.png"), 0, 0, null);
		g.drawImage(t.getImage("images/Menu/menu.png"), 450, 300, null);
		g.drawImage(t.getImage("images/Menu/Esci.png"), 460, 400, null);
		//this.repaint();
		int x=150;
		int y=300;
		
		g.setColor(Color.RED);
		g.drawString("POS", x-37, y-50);
		g.drawString(" NOME ", x+10, y-50);
		g.drawString(" PUNTEGGIO ", x+100, y-50);
		
		g.setColor(Color.YELLOW);
		for ( int i=0; i<10; i++ ){
			g.drawString(mf.classifica.getitem().get(i).getNome(), x, y);
			g.drawString(" -> "+mf.classifica.getitem().get(i).getPunti(), x+100, y);
			g.drawString(""+(i+1), x-30, y);
			y=y+20;
		}
	}
	

	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		if (e.getKeyCode() == KeyEvent.VK_SPACE) {
			mf.menu();		
		}
		else if (e.getKeyCode() == KeyEvent.VK_Q) {
			System.exit(0);
		}
	}


	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
	}

	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
	}
}
